<?php namespace Admin\Controller; 

use Admin\Model\Cat;

class CatController extends AuthController{
	//驱动连接
	protected $db;

	//构造函数
	public function __construct()
	{
		$this->db = new Cat;
	}
	
    //动作
    public function index(){
       	$data = $this->db->getAll();
		View::with('data',$data);
		View::make();
    }

    //增加栏目
    public function add()
    {
    	if (IS_POST) 
    	{
    		if($this->db->store())
			{
				View::success('添加成功',U('index'));
			}
			else
			{
				View::error($this->db->getError());
			}
    	}
    	else{
            $type = new \Admin\Model\ShopType;
            $ShopType = $type->getAll();
            View::with('ShopType',$ShopType);

    		$data = $this->db->getAll();
    		View::with('data',$data)->make();
    	}

    }

    //编辑栏目
    public function edit()
    {
    	if (IS_POST)
    	{
    		if($this->db->edit())
			{
				View::success('操作成功',U('index'));
			}
			else
			{
				View::error($this->db->getError());
			}
    	}
    	else{
    		//获取单挑数据
    		$data = $this->db->only($_GET['cat_id']);
    		$cat = $this->db->getAll();

            $type = new \Admin\Model\ShopType;
            $ShopType = $type->getAll();
            View::with('ShopType',$ShopType);
    		View::with('data',$data)->with('cat',$cat)->make();
    	}
    }
}
